﻿cmake_minimum_required(VERSION 2.8)
project(avutil)
file(GLOB lib_hdrs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h)
file(GLOB lib_asms RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} x86/*.asm)
file(GLOB lib_srcs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} x86/*.c)
list(FILTER lib_asms EXCLUDE REGEX ".*x86util.asm|.*x86inc.asm")
set(lib_srcs ${lib_srcs}
  adler32.c
  aes.c
  aes_ctr.c
  audio_fifo.c
  avstring.c
  avsscanf.c
  base64.c
  blowfish.c
  bprint.c
  buffer.c
  cast5.c
  camellia.c
  channel_layout.c
  color_utils.c
  cpu.c
  crc.c
  des.c
  dict.c
  display.c
  dovi_meta.c
  downmix_info.c
  encryption_info.c
  error.c
  eval.c
  fifo.c
  file.c
  file_open.c
  float_dsp.c
  fixed_dsp.c
  frame.c
  hash.c
  hdr_dynamic_metadata.c
  hmac.c
  hwcontext.c
  imgutils.c
  integer.c
  intmath.c
  lfg.c
  lls.c
  log.c
  log2_tab.c
  mathematics.c
  mastering_display_metadata.c
  md5.c
  mem.c
  murmur3.c
  opt.c
  parseutils.c
  pixdesc.c
  pixelutils.c
  random_seed.c
  rational.c
  reverse.c
  rc4.c
  ripemd.c
  samplefmt.c
  sha.c
  sha512.c
  slicethread.c
  spherical.c
  stereo3d.c
  threadmessage.c
  time.c
  timecode.c
  tree.c
  twofish.c
  utils.c
  xga_font_data.c
  xtea.c
  tea.c
  tx.c
  tx_float.c
  tx_double.c
  tx_int32.c
  video_enc_params.c
  film_grain_params.c
  avutilres.rc
  hwcontext_d3d11va.c
  hwcontext_dxva2.c
  lzo.c
  avutil-56.def
)
set(CMAKE_DEBUG_POSTFIX "D")

macro(cl_asm)
  foreach(_var ${ARGN})
    list(APPEND lib_objs ${_var}.obj)
	file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${_var} src)
	file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/${_var}.obj dst)
    add_custom_command(OUTPUT ${dst}
	  COMMAND cd ARGS ${CMAKE_CURRENT_SOURCE_DIR}/..
	  COMMAND yasm ARGS -I. -P config.asm -f win64 ${src} -o ${dst} MAIN_DEPENDENCY ${_var})
  endforeach()
endmacro()
cl_asm(${lib_asms})

include_directories(.. ../compat ../compat/atomics/win32 x86)
add_definitions(-DHAVE_AV_CONFIG_H)
add_library(${PROJECT_NAME} SHARED ${lib_srcs} ${lib_asms} ${lib_objs})
target_link_libraries(${PROJECT_NAME} ${lib_libs} bcrypt)
install(FILES ${lib_hdrs} DESTINATION include/ffmpeg/lib${PROJECT_NAME})
install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}-targets RUNTIME DESTINATION bin ARCHIVE DESTINATION lib)
install(EXPORT ${PROJECT_NAME}-targets DESTINATION lib/cmake FILE ${PROJECT_NAME}-config.cmake)

if(BUILD_STATIC)
  add_library(${PROJECT_NAME}S STATIC ${lib_srcs} ${lib_asms} ${lib_objs})
  install(TARGETS ${PROJECT_NAME}S EXPORT ${PROJECT_NAME}S-targets RUNTIME DESTINATION bin ARCHIVE DESTINATION lib)
  install(EXPORT ${PROJECT_NAME}S-targets DESTINATION lib/cmake FILE ${PROJECT_NAME}S-config.cmake)
endif()

